﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Jzy.Workflow.Flow;
using System.Xml.Linq;

namespace Jzy.Web.WorkFlow.Design
{
    public partial class Download : System.Web.UI.Page
    {
        private string FlowID
        {
            get
            {
                return Request.QueryString["FlowID"];
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            FlowBO flow = new FlowBO();
            FlowInfo flowInfo = flow.GetInfo(FlowID);
            if (!string.IsNullOrEmpty(flowInfo.FormTemplate))
            {
                XElement html = XElement.Parse(flowInfo.FormTemplate);
                string strHtml = "<html><head>" + html.Element("head").Value + "</head>" +
                                "<body>" + html.Element("body").Value + "</body></html>";

                Response.AddHeader("Content-Disposition", "attachment; filename=" + Server.UrlEncode(flowInfo.Name) + ".htm");
                Response.ContentType = "text/plain";
                Response.ContentEncoding = System.Text.Encoding.UTF8;
                Response.Write(strHtml);
                Response.End();
            }
        }
    }
}
